package org.dut.book.Mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.dut.book.model.BookInfo;
import org.dut.book.model.PageRequest;

import java.util.List;

@Mapper
public interface BookMapper {

    @Select("select * from book_info where status != 0 order by id limit #{offset},#{pageSize}")
    List<BookInfo> selectBookInfoByPage(PageRequest pageRequest);

    @Select("select count(1) from book_info where status != 0")
    Integer countAllBookInfo();

    @Insert("insert into book_info(book_name, author, count, price, publish,status) values" +
            " (#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer insertBook(BookInfo book);

    @Select("select * from book_info where id = #{id}")
    BookInfo selectBookById(Integer id);

    //动态 SQL
    Integer updateBook(BookInfo book);

    //逻辑删除
    @Update("update book_info set status = 0 where  id = #{id}")
    Boolean deleteBookById(Integer id);

    Integer deleteBookByIds(Integer[] ids);
}
